const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const Answer = {};

const answerSchema = new mongoose.Schema({
    _id: Schema.Types.ObjectId,
    content: String,
    createTime: Date,
    like: {
        type: Number,
        default: 0
    },
    questions: {
        type: Schema.Types.ObjectId,
        ref: 'questions'
    },
    author: {
        type: Schema.Types.ObjectId,
        ref: 'users'
    }
})

Answer.Model = mongoose.model('answers', answerSchema);

Answer.Model.on('index', err => {
    if (err) {
        console.error('集合 keywords 索引错误！', err)
    } else {
        console.log('集合 Answer 索引成功...')
    }
})

module.exports = Answer;
